﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZhouYu.NewWorld.BLL.IService;
using ZhouYu.NewWorld.Model;
using ZhouYu.NewWorld.ViewModel;

namespace ZhouYu.NewWorld.Web.Controllers
{
    public class GoodsController : Controller
    {
        //注入
        private IGoodsService _goodsService;
        public GoodsController(IGoodsService goodsService)
        {
            _goodsService = goodsService;
        }
        

        // GET: Goods
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 多表查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public JsonResult GetGoodsInfo(int page,int limit) 
        {
            ResponseResult result = new ResponseResult();
            result = _goodsService.GetGoodsInfo(page,limit);
            return Json(result,JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 多表添加
        /// </summary>
        /// <param name="goodsCustom"></param>
        /// <returns></returns>
        public JsonResult AddGoods(GoodsCustom goodsCustom) 
        {
            ResponseResult result = new ResponseResult();
            result.data = _goodsService.AddGoods(goodsCustom);
            return Json(result);
        }

        /// <summary>
        /// 多表编辑
        /// </summary>
        /// <param name="goodsCustom"></param>
        /// <returns></returns>
        public JsonResult UpdateGoods(GoodsCustom goodsCustom)
        {
            ResponseResult result = new ResponseResult();
            result.data = _goodsService.UpdateGoods(goodsCustom);
            return Json(result);
        }

        /// <summary>
        /// 多表删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteGoods(int id)
        {
            ResponseResult result = new ResponseResult();
            result = _goodsService.DeleteGoods(id);
            return Json(result);
        }
    }
}